<?php
CUserAuth::hasAccess(STATUS_MITARBEITER_SCHREIBEN);
/** costumers_edit.php
 * Project name: project_name
 * Created on: 23.11.2011
 * Author: Matias Thomsen
 * 
 * Kunden auswahl aus einer Tabelle und anschlißende Bearbeitungsmaske.
 */
//CUserAuth::hasAccess(STATUS_MITARBEITER_SCHREIBEN);

if (isset($_POST['abort'])) {
        header("LOCATION: ?page=customer-view");
        die("Fatal error!");
}

//-----INCLUDES-----
    include_once 'class/customer/CCustomerMapper.php';
//-----INCLUDES END-----    
    
//-----DATABASE CONNECTION-----
    $db = new CCustomerMapper($connArgs);
//-----DATABASE CONNECTION END-----

//-----VARS---------------------------------------------------------------------
    $showCustomerTable = true;
//-----VARS END-----------------------------------------------------------------
    
//-----VARS-----
    $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = ""; $sel5 = ""; $sel6 = ""; //select box
    $errors = array(); // array to sumarize errors
    $staff = $_SESSION['userID']; //employee logged in
    $gstelle = $_SESSION['gstelleId']; //employees' workstation
    $show_editForm = true;
//-----VARS END-----
    
//---------------------------------------
//-----TABLE WITH SELECTED CUSTOMER------
//---------------------------------------
    
    if ( isset($_GET['kunden-nr']) ){
        if ( $_GET['ib'] == "1" ){
            $customerEdit = $db->getSingleCustomer($_GET['kunden-nr'], 1);
        }elseif ( $_GET['ib'] == "0" ){
            $customerEdit = $db->getSingleCustomer($_GET['kunden-nr'], 0);
        }else{
            exit;
        }
            $showCustomerTable = false; //disable table with customers
//            if ( $customerEdit == "inBearbeitung"){
//                $errors[] = "Der Kunde hat bereits eine Bearbeitngsaufforderng, "
//                            . "welche akzeptiert oder abgeleht werden muss, bevor er erneut bearbeitet werden kann";
//            }
            if ( $customerEdit != false ){  
                
                    //-----FORMULAR DATA-----
                    // <editor-fold defaultstate="collapsed" desc="FORMULAR DATA">
                    //Needed for comboboxes
                    
                    //betreuer array
                    $query = "SELECT `idMitarbeiter`, `name`, `vorname` 
                                        FROM `Mitarbeiter`
                                        WHERE `gstelleId` = '$gstelle'";
                    $stm = $db->prepare($query);
                    $stm->execute();
                    $betreuer = $stm->fetchAll(PDO::FETCH_ASSOC);


                    //branche array
                    $query = "SELECT * 
                                        FROM `Branche`";
                    $stm = $db->prepare($query);
                    $stm->execute();
                    $branchen = $stm->fetchAll(PDO::FETCH_ASSOC);


                    //beruf array
                    $query = "SELECT *
                                        FROM `Beruf`";
                    $stm = $db->prepare($query);
                    $stm->execute();
                    $berufe = $stm->fetchAll(PDO::FETCH_ASSOC);


                    //berufGruppe array
                    $query = "SELECT * 
                                        FROM `Berufsgruppe`";
                    $stm = $db->prepare($query);
                    $stm->execute();
                    $berufsgruppe = $stm->fetchAll(PDO::FETCH_ASSOC);


                    //-----FORMULAR DATA END-----// </editor-fold>
                    

                    //-----IF CREATE FORM IS FIRED-----                            
                    // <editor-fold defaultstate="collapsed" desc="IF EDIT FORM IS FIRED">
                    if (isset($_POST['mark']) || isset($_POST['save'])) {
                        $customer = new CCustomer();


                        //anrede--------------------------------------------------------------------
                        if (isset($_POST['anrede']) && $_POST['anrede'] != "") {
                            switch ($_POST['anrede']) {
                                case '1': $customer->setAnrede("herr");
                                    break;
                                case '2': $customer->setAnrede("frau");
                                    break;


                                default:

                                    if (isset($_POST['mark'])) {
                                        $errors[] = "Bitte wählen Sie die passende Anrede";
                                    } elseif (isset($_POST['save'])) {
                                        $customer->setAnrede("NA");
                                    }


                                    break;
                            }
                        } else {
                            die("Fatal error!");
                        }


                        //titel--------------------------------------------------------------------
                        if (isset($_POST['titel']) && $_POST['titel'] != "") {
                            switch ($_POST['titel']) {
                                case '1': $customer->setTitel("kein_titel");
                                    break;
                                case '2': $customer->setTitel("dr");
                                    break;
                                case '3': $customer->setTitel("prof");
                                    break;
                                case '4': $customer->setTitel("dr_prof");
                                    break;


                                default: $customer->setTitel("kein_titel");
                                    break;
                            }
                        } else {
                            die("Fatal error!");
                        }


                        //vorname--------------------------------------------------------------------
                        if (isset($_POST['firstname']) && $_POST['firstname'] != "") {
                            $customer->setName($_POST['firstname']);
                        } else {
                            $errors[] = "Bitte geben Sie den Vorname an.";
                        }


                        //nachname--------------------------------------------------------------------
                        if (isset($_POST['lastname']) && $_POST['lastname'] != "") {
                            $customer->setNachname($_POST['lastname']);
                        } else {
                            $errors[] = "Bitte geben Sie den Nachname an.";
                        }


                        //geburtsname-------------------------------------------------------------------
                        if (isset($_POST['birthname']) && $_POST['birthname'] != "") {
                            $customer->setGeburtsname($_POST['birthname']);
                        } else {
                            $customer->setGeburtsname(null);
                        }


                        //strasse_nr--------------------------------------------------------------------
                        if (isset($_POST['adress']) && $_POST['adress'] != "") {
                            $customer->setStrasse_nr($_POST['adress']);
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben Sie die Adresse (Straße, Nummer) an";
                            } elseif (isset($_POST['save'])) {
                                $customer->setStrasse_nr(null);
                            }
                        }


                        //plz---------------------------------------------------------------------------
                        if (isset($_POST['zipcode']) && $_POST['zipcode'] != "") {
                            $customer->setPlz($_POST['zipcode']);
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben Sie die PLZ an";
                            } elseif (isset($_POST['save'])) {
                                $customer->setPlz(null);
                            }
                        }


                        //ort---------------------------------------------------------------------------
                        if (isset($_POST['city']) && $_POST['city'] != "") {
                            $customer->setOrt($_POST['city']);
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben Sie den Wohnort an.";
                            } elseif (isset($_POST['save'])) {
                                $customer->setOrt(null);
                            }
                        }


                        //wohnhaftSeit------------------------------------------------------------------
                        if (isset($_POST['livingsince']) && $_POST['livingsince'] != "") {
                            $timestamp = strtotime($_POST['livingsince']);


                            if (date("d.m.Y", $timestamp) == $_POST['livingsince']) {
                                $customer->setWohnhaftSeit(date("Y-m-d", $timestamp));
                            } else {
                                $errors[] = "Bitte geben Sie das Datum im richtigen Format ein (Feld: Wohnhaft Seit)";
                            }
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben an, seit wann Sie bei der Aktuellen Adresse wohnen.";
                            } elseif (isset($_POST['save'])) {
                                $customer->setWohnhaftSeit("0000-00-00");
                            }
                        }


                        //geburtsdatum------------------------------------------------------------------
                        if (isset($_POST['birthdate']) && $_POST['birthdate'] != "") {
                            $timestamp = strtotime($_POST['birthdate']);
                            if (date("d.m.Y", $timestamp) == $_POST['birthdate']) {
                                $customer->setGeburtsdatum(date("Y-m-d", $timestamp));
                            } else {
                                $errors[] = "Bitte geben Sie das Datum im richtigen Format ein (Feld: Geburtsdatum)";
                            }
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben Sie das Geburtsdatum an.";
                            } elseif (isset($_POST['save'])) {
                                $customer->setGeburtsdatum("0000-00-00");
                            }
                        }


                        //fam_stand---------------------------------------------------------------------
                        if (isset($_POST['fam_stand']) && $_POST['fam_stand'] != "") {
                            switch ($_POST['fam_stand']) {
                                case '1': $customer->setFamilienstand("1");
                                    break;
                                case '2': $customer->setFamilienstand("2");
                                    break;
                                case '3': $customer->setFamilienstand("3");
                                    break;
                                case '4': $customer->setFamilienstand("4");
                                    break;
                                case '5': $customer->setFamilienstand("5");
                                    break;
                                case '6': $customer->setFamilienstand("6");
                                    break;


                                default:

                                    if (isset($_POST['mark'])) {
                                        $errors[] = "Bitte wählen Sie den passenden Familienstand";
                                    } elseif (isset($_POST['save'])) {
                                        $customer->setFamilienstand("NA");
                                    }
                                    break;
                            }
                        } else {
                            die("Fatal Error");
                        }


                        //staatsange--------------------------------------------------------------------
                        if (isset($_POST['nacionality']) && $_POST['nacionality'] != "") {
                            $customer->setStaatsange($_POST['nacionality']);
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben Sie die Staatsangehörigkeit an.";
                            } elseif (isset($_POST['save'])) {
                                $customer->setStaatsange(null);
                            }
                        }


                        //telefon_1---------------------------------------------------------------------
                        if (isset($_POST['phone_1']) && $_POST['phone_1'] != "") {
                            $customer->setTelefon_1($_POST['phone_1']);
                        } else {
                            $customer->setTelefon_1('');
                        }


                        //telefon_2---------------------------------------------------------------------
                        if (isset($_POST['phone_2']) && $_POST['phone_2'] != "") {
                            $customer->setTelefon_2($_POST['phone_2']);
                        } else {
                            $customer->setTelefon_2('');
                        }


                        //email-------------------------------------------------------------------------
                        if (isset($_POST['email']) && $_POST['email'] != "") {
                            if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                                $customer->setEmail($_POST['email']);
                            } else {
                                if (isset($_POST['mark'])) {
                                    $errors[] = "Die angegebene E-Mail ist nicht gültig";
                                } elseif (isset($_POST['save'])) {
                                    $customer->setEmail(null);
                                }
                            }
                        
                                } else {
                            $customer->setEmail('');
                        }


                        //datenschutz-------------------------------------------------------------------
                        if (isset($_POST['privacy'])) {
                            if ($_POST['privacy'] == "accepted") {
                                $customer->setDatenschutz(1);
                            } else {
                                $customer->setDatenschutz(0);
                            }
                        } else {
                            $customer->setDatenschutz(0);
                        }


                        //monatEinkommen----------------------------------------------------------------
                        if (isset($_POST['month']) && $_POST['month'] != "") {
                            $customer->setMonatEinkommen($_POST['month']);
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben Sie das Monatseinkommen an.";
                            } elseif (isset($_POST['save'])) {
                                $customer->setExtraEinkommen(null);
                            }
                        }


                        //extraEinkommen----------------------------------------------------------------
                        if (isset($_POST['extra']) && $_POST['extra'] != "") {
                            $customer->setExtraEinkommen($_POST['extra']);
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben Sie das Extra Einkommen an.";
                            } elseif (isset($_POST['save'])) {
                                $customer->setExtraEinkommen(null);
                            }

                        }

                        //fam_stand---------------------------------------------------------------------
                        if (isset($_POST['living_at']) && $_POST['living_at'] != "") {
                            switch ($_POST['living_at']) {
                                case '1': $customer->setWohnsituation("miete");
                                    break;
                                case '2': $customer->setWohnsituation("eltern");
                                    break;
                                case '3': $customer->setWohnsituation("eigentum");
                                    break;


                                default:

                                    if (isset($_POST['mark'])) {
                                        $errors[] = "Bitte wählen Sie die Wohnsituation aus";
                                    } elseif (isset($_POST['save'])) {
                                        $customer->setWohnsituation("NA");
                                    }
                                    break;
                            }
                        } else {
                            die("Fatal Error");
                        }
                        
                        
                        //brancheId---------------------------------------------------------------------
                        if (isset($_POST['sector']) && $_POST['sector'] != "") {
                            $customer->setBrancheId($_POST['sector']);
                        } else {
                            $customer->setBrancheId(9999);
                        }


                        //berufsgruppeId----------------------------------------------------------------
                        if (isset($_POST['sector_group']) && $_POST['sector_group'] != "") {
                            $customer->setBerufsgruppeId($_POST['sector_group']);
                        } else {
                            if (isset($_POST['mark'])) {
                                $errors[] = "Bitte geben Sie die Berufsgruppe an.";
                            } elseif (isset($_POST['save'])) {
                                $customer->setBerufsgruppeId(9999);
                            }
                        
                                }


                        //berufId-----------------------------------------------------------------------
                        if (isset($_POST['occupation']) && $_POST['occupation'] != "") {
                            $customer->setBerufId($_POST['occupation']);
                        } else {
                            $customer->setBerufId(9999);
                        }


                        //betreuerId--------------------------------------------------------------------
                        if ( isset( $_POST['advisor'] ) && $_POST['advisor'] != "" && $_POST['advisor'] != 9999){
                                $customer->setBetreuerId($_POST['advisor']);
                        }else{
                                $customer->setBetreuerId(null);

                        }


                        //SAVE IF NO ERRORS
                        if (count($errors) == 0) {
                            $customer->setKundenNr($customerEdit->getKundenNr());
                            $customer->setGstelleId($gstelle);
                            $customer->setBearbeiterId($staff);

                            if (isset($_POST['mark'])) {
                                    $result = $db->deleteCustomer($customer, 1); //delete dummy
                                    
                                    $customer->setStatus(2); //marked
                                    $customer->setInBearbeitung(1); //copy of the active customer
                                    
                                    $result = $db->saveCustomer($customer); //save dataset
                                    if ( $result == 1 ){
                                        $message = "Der Kunde wurde zur Freigabe vorgemerkt.";
                                    }
                                
                                
                            }elseif (isset($_POST['save'])) {
                                    $result = $db->deleteCustomer($customer, 1); //delete dummy
                                    
                                    $customer->setStatus(6); //marked
                                    $customer->setInBearbeitung(1); //copy of the active customer
                                    
                                    $result = $db->saveCustomer($customer); //save dataset
                                    if ( $result == 1 ){
                                        $message = "Der Kunde unvolständig gespeichert.";
                                    }
                            }else{
                                    $errors[] = "Bitte wählen Sie einen Kunden unter <a href=\"?page=customer-edit&action=mark\">Kunden Bearbeiten</a> aus.";
                            }


                            
                            
                                        //display error or success message
                            if ($result != 1) {
                                $errors[] = $result;
                            } else {
                                $show_editForm = false; //disable form editing
                                ?>
                                    <div id="message-box">
                                            <p><?= $message ?></p>
                                    </div>
                                <?php
                            }
                        
                                }
                        //SAVE IF NO ERRORS
                    }//IF CREATE FORM IS FIRED END// </editor-fold>
                                
                    ?>

                    <?php
                    //IF OPTIONS FORM IS FIRED END
                        if ( $show_editForm == true ){ //display editForm if true
                    ?>
                    <!-- EDIT FORM START -->

                    <?php
                        if ( count($errors) > 0 ){
                    ?>
                                <!-- Error message box -->
                                <div class="display-errors-label">
                                        Die Daten konnten nicht gespeichert werden
                                </div>
                                <div class="display-errors-massage">
                                        <ul>
                                        <?php
                                            foreach ( $errors as $error ){
                                                    echo "<li>".$error."</li>";
                                            }
                                        ?>
                                        </ul>
                                </div>
                    <?php } ?>
                    <!-- Error message box end -->

                    <div class="form-customer-create">
                            <!-- 2 columns -->
                            <div class="form-customer-create-2cols">

                                    <!-- FORM-HEADLINE -->
                                    <div class="form-customer-create-headline">Standard angaben</div>
                                    <!-- FORM-HEADLINE END -->

                                    <!-- ########################################################## -->
                                    <!-- Form Start -->
                                    <form name = "create" method="POST" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>">
                                            <!-- ########################################################## -->
                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Anrede*</div>
                                                    <div class="form-customer-create-input">
                                                        <?php
                                                        if ( isset($_POST['anrede']) ){
                                                                switch ( $_POST['anrede'] ){
                                                                    case "1": $sel1 = " selected"; break;
                                                                    case "2": $sel2 = " selected"; break;
                                                                    default:  $sel1 = ""; $sel2 = ""; break;
                                                                }
                                                        }else{
                                                                switch ( $customerEdit->getAnrede() ){
                                                                    case "Herr": $sel1 = " selected"; break;
                                                                    case "Frau": $sel2 = " selected"; break;
                                                                    default:  $sel1 = ""; $sel2 = ""; break;
                                                                }
                                                        }
                                                        ?>
                                                            <select name="anrede">
                                                                    <option value="0">keine Angabe</option>
                                                                    <option value="1"<?= $sel1 ?>>Herr</option>
                                                                    <option value="2"<?= $sel2 ?>>Frau</option>
                                                            </select>
                                                    </div>
                                                    <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">                        
                                                    <div class="form-customer-create-label">Titel*</div>
                                                    <div class="form-customer-create-input">
                                                        <?php
                                                        if ( isset($_POST['titel']) ){
                                                            
                                                                switch ( $_POST['titel'] ){
                                                                    case "1": $sel1 = " selected"; break;
                                                                    case "2": $sel2 = " selected"; break;
                                                                    case "3": $sel3 = " selected"; break;
                                                                    case "4": $sel4 = " selected"; break;
                                                                    default:  $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = "";
                                                                }
                                                        }else{
                                                                switch ( $customerEdit->getTitel() ){ 
                                                                    case "Kein_titel": $sel1 = " selected"; break;
                                                                    case "Dr": $sel2 = " selected"; break;
                                                                    case "Prof": $sel3 = " selected"; break;
                                                                    case "Dr_Prof": $sel4 = " selected"; break;
                                                                    default:  $sel1 = " selected"; $sel2 = ""; $sel3 = ""; $sel4 = "";
                                                                }
                                                        }
                                                        ?>
                                                            <select name="titel">
                                                                    <option value="1"<?= $sel1 ?>>Kein Titel</option>
                                                                    <option value="2"<?= $sel2 ?>>Dr.</option>
                                                                    <option value="3"<?= $sel3 ?>>Prof.</option>
                                                                    <option value="4"<?= $sel4 ?>>Prof. Dr.</option>
                                                            </select>
                                                    </div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->
                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->
                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Vorname*#</div>
                                                    <div class="form-customer-create-input"><input type="text" name="firstname" value="<?php if ( isset($_POST['firstname']) ){echo $_POST['firstname'];}else{ echo $customerEdit->getName(); } ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Nachname*#</div>
                                                    <div class="form-customer-create-input"><input type="text" name="lastname" value="<?php if ( isset($_POST['lastname']) ){echo $_POST['lastname'];}else{ echo $customerEdit->getNachname(); } ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Geburtsname</div>
                                                    <div class="form-customer-create-input"><input type="text" name="birthname" value="<?php if ( isset($_POST['birthname']) ){echo $_POST['birthname'];}else{ echo $customerEdit->getGeburtsname(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Stra&szlig;e, Nr*</div>
                                                    <div class="form-customer-create-input"><input type="text" name="adress" value="<?php if ( isset($_POST['adress']) ){echo $_POST['adress'];}else{ echo $customerEdit->getStrasse_nr(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">PLZ*</div>
                                                    <div class="form-customer-create-input"><input type="text" name="zipcode" value="<?php if ( isset($_POST['zipcode']) ){echo $_POST['zipcode'];}else{ echo $customerEdit->getPlz(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Stadt*</div>
                                                    <div class="form-customer-create-input"><input type="text" name="city" value="<?php if ( isset($_POST['city']) ){echo $_POST['city'];}else{ echo $customerEdit->getOrt(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Wohnhaft seit*</div>
                                                    <div class="form-customer-create-input"><input id="datepicker_livingsince" type="text" name="livingsince" value="<?php if ( isset($_POST['livingsince']) ){echo $_POST['livingsince'];}else{ echo readableDate($customerEdit->getWohnhaftSeit()); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Geburtsdatum*</div>
                                                    <div class="form-customer-create-input"><input id="datepicker_birthday" type="text" name="birthdate" value="<?php if ( isset($_POST['birthdate']) ){echo $_POST['birthdate'];}else{ echo readableDate($customerEdit->getGeburtsdatum()); }  ?>"/></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Familienstand*</div>
                                                    <div class="form-customer-create-input">
                                                        <?php
                                                        if ( isset($_POST['fam_stand']) ){
                                                                switch ( $_POST['fam_stand'] ){
                                                                    case "1": $sel1 = " selected"; break;
                                                                    case "2": $sel2 = " selected"; break;
                                                                    case "3": $sel3 = " selected"; break;
                                                                    case "4": $sel4 = " selected"; break;
                                                                    case "5": $sel5 = " selected"; break;
                                                                    case "6": $sel6 = " selected"; break;
                                                                    default:  $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = ""; $sel5 = ""; $sel6 = "";
                                                                }
                                                        }else{
                                                                switch ( $customerEdit->getFamilienstand() ){
                                                                    case "1": $sel1 = " selected"; break;
                                                                    case "2": $sel2 = " selected"; break;
                                                                    case "3": $sel3 = " selected"; break;
                                                                    case "4": $sel4 = " selected"; break;
                                                                    case "5": $sel5 = " selected"; break;
                                                                    case "6": $sel6 = " selected"; break;
                                                                    default:  $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = ""; $sel5 = ""; $sel6 = "";
                                                                }
                                                        }
                                                        ?>
                                                            <select name="fam_stand">
                                                                    <option value="0">keine Angabe</option>
                                                                    <option value="1"<?= $sel1 ?>>Ledig</option>
                                                                    <option value="2"<?= $sel2 ?>>Verheiratet</option>
                                                                    <option value="3"<?= $sel3 ?>>Geschieden</option>
                                                                    <option value="4"<?= $sel4 ?>>Zusammenlebend</option>
                                                                    <option value="5"<?= $sel5 ?>>Getrennt lebend</option>
                                                                    <option value="6"<?= $sel6 ?>>verwitwet</option>
                                                            </select>
                                                    </div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Staatsangeh&ouml;rigkeit*</div>
                                                    <div class="form-customer-create-input"><input type="text" name="nacionality" value="<?php if ( isset($_POST['nacionality']) ){echo $_POST['nacionality'];}else{ echo $customerEdit->getStaatsange(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Telefonnummer 1</div>
                                                    <div class="form-customer-create-input"><input type="text" name="phone_1" value="<?php if ( isset($_POST['phone_1']) ){echo $_POST['phone_1'];}else{ echo $customerEdit->getTelefon_1(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Telefonnummer 2</div>
                                                    <div class="form-customer-create-input"><input type="text" name="phone_2" value="<?php if ( isset($_POST['phone_2']) ){echo $_POST['phone_2'];}else{ echo $customerEdit->getTelefon_2(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">E-Mail</div>
                                                    <div class="form-customer-create-input"><input type="text" name="email" value="<?php if ( isset($_POST['email']) ){echo $_POST['email'];}else{ echo $customerEdit->getEmail(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">&nbsp;</div>
                                                    <div class="form-customer-create-input">&nbsp;</div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- FORM-HEADLINE -->
                                            <div class="form-customer-create-headline">Zusatz angaben</div>
                                            <!-- FORM-HEADLINE END -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Monatseinkommen*</div>
                                                    <div class="form-customer-create-input"><input type="text" name="month" value="<?php if ( isset($_POST['month']) ){echo $_POST['month'];}else{ echo $customerEdit->getMonatEinkommen(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Extra-Einkommen*</div>
                                                    <div class="form-customer-create-input"><input type="text" name="extra" value="<?php if ( isset($_POST['extra']) ){echo $_POST['extra'];}else{ echo $customerEdit->getExtraEinkommen(); }  ?>" /></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Wohnsituation*</div>
                                                    <div class="form-customer-create-input">
                                                        <?php
                                                        if ( isset($_POST['living_at']) ){
                                                                switch ( $_POST['living_at'] ){
                                                                    case "1": $sel1 = " selected"; break;
                                                                    case "2": $sel2 = " selected"; break;
                                                                    case "3": $sel3 = " selected"; break;
                                                                    default: $sel1 = ""; $sel2 = ""; $sel3 = "";
                                                                }
                                                        }else{
                                                                switch ( $customerEdit->getWohnsituation() ){
                                                                    case "miete": $sel1 = " selected"; break;
                                                                    case "eltern": $sel2 = " selected"; break;
                                                                    case "eigentum": $sel3 = " selected"; break;
                                                                    default: $sel1 = ""; $sel2 = ""; $sel3 = "";
                                                                }
                                                        }
                                                        ?>
                                                            <select name="living_at">
                                                                    <option value="0">keine Angabe</option>
                                                                    <option value="1"<?= $sel1 ?>>Miete</option>
                                                                    <option value="2"<?= $sel2 ?>>Eltern</option>
                                                                    <option value="3"<?= $sel3 ?>>Eigentum</option>
                                                            </select>
                                                    </div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Berufsgruppe*</div>
                                                    <div class="form-customer-create-input">
                                                            <select id="sector_group" name="sector_group">
                                                                <option value="9999">keine Angabe</option>
                                                                <?php
                                                                foreach ( $berufsgruppe as $value ){
                                                                        if ( isset($_POST['sector_group']) ){
                                                                                if ( $_POST['sector_group'] == $value['idBerufsgruppe'] ){
                                                                                        $selected = " selected";
                                                                                }else{
                                                                                        $selected = "";
                                                                                }
                                                                        }else{
                                                                                if ( $customerEdit->getBerufsgruppeId() == $value['idBerufsgruppe'] ){
                                                                                        $selected = " selected";
                                                                                }else{
                                                                                        $selected = "";
                                                                                }
                                                                        }
                                                                        echo "<option value=\"".$value['idBerufsgruppe']."\"$selected>".$value['bezeichnung']."</option>\n";
                                                                }
                                                                ?>
                                                            </select>
                                                    </div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div id="sector" class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Branche</div>
                                                    <div class="form-customer-create-input">
                                                            <select id="sb_sector" name="sector">
                                                                <option value="9999">keine Angabe</option>
                                                                <?php
                                                                foreach ( $branchen as $value ){
                                                                        if ( isset($_POST['sector']) ){
                                                                                if ( $_POST['sector'] == $value['idBranche'] ){
                                                                                    $selected = " selected";
                                                                                }else{
                                                                                    $selected = "";
                                                                                }
                                                                        }else{
                                                                                if ( $customerEdit->getBrancheId() == $value['idBranche'] ){
                                                                                    $selected = " selected";
                                                                                }else{
                                                                                    $selected = "";
                                                                                }
                                                                        }
                                                                        echo "<option value=\"".$value['idBranche']."\"$selected>".$value['bezeichnung']."</option>\n";
                                                                }
                                                                ?>
                                                            </select>
                                                    </div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div id="occupation" class="form-customer-create-input-wrap">
                                                    <div id="label_occupation" class="form-customer-create-label">Beruf</div>
                                                    <div class="form-customer-create-input">
                                                        <select id="sb_occupation" name="occupation">
                                                                <option value="9999">keine Angabe</option>
                                                                <?php
                                                                foreach ( $berufe as $value ){
                                                                        if ( isset($_POST['occupation']) ){
                                                                                if ( $_POST['occupation'] == $value['idBeruf'] ){
                                                                                        $selected = " selected";
                                                                                }else{
                                                                                        $selected = "";
                                                                                }
                                                                        }else{
                                                                                if ( $customerEdit->getBerufId() == $value['idBeruf'] ){
                                                                                        $selected = " selected";
                                                                                }else{
                                                                                        $selected = "";
                                                                                }
                                                                        }
                                                                        echo "<option value=\"".$value['idBeruf']."\"$selected>".$value['bezeichnung']."</option>\n";
                                                                }
                                                                ?>
                                                            </select>
                                                    </div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- FORM-HEADLINE -->
                                            <div class="form-customer-create-headline">Intern</div>
                                            <!-- FORM-HEADLINE END -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Einwilligung wurde abgegeben</div>
                                                    <div class="form-customer-create-input"><input type="checkbox" name="privacy" value="accepted" <?php if ( isset($_POST['privacy']) ){echo "checked"; }else{ if ( $customerEdit->getDatenschutz() == 1 ) { echo "checked";}} ?>/></div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-input-wrap">
                                                    <div class="form-customer-create-label">Betreuer</div>
                                                    <div class="form-customer-create-input">
                                                            <select name="advisor">
                                                                <option value="9999">keine Angabe</option>
                                                                <?php
                                                                foreach ( $betreuer as $value ){
                                                                        if ( isset($_POST['advisor']) ){
                                                                                if ( $_POST['advisor'] == $value['idMitarbeiter'] ){
                                                                                        $selected = " selected";
                                                                                }else{
                                                                                        $selected = "";
                                                                                }
                                                                        }else{
                                                                                if ( $customerEdit->getBetreuerId() == $value['idMitarbeiter'] ){
                                                                                        $selected = " selected";
                                                                                }else{
                                                                                        $selected = "";
                                                                                }
                                                                        }
                                                                        echo "<option value=\"".$value['idMitarbeiter']."\"$selected>".utf8_encode($value['name']).", ".utf8_encode($value['vorname'])."</option>\n";
                                                                }
                                                                ?>
                                                            </select>
                                                    </div>
                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                            <!-- ########################################################## -->

                                            <!-- Form element wrap -->
                                            <div class="form-customer-create-submit-wrap">
                                                    <div>* Pflichtfelder für die Vormerkung zur Freigabe<br /># Pflichtfelder für das unvolständige Speichern</div>
                                                    <div class="form-customer-create-submit">
                                                        <input class="form-customer-create-button" type="submit" name="abort" value="Abbrechen"/>
                                                        <?php if ( isset($customerEdit) ){
                                                            if ( $customerEdit->getInBearbeitung() !== null ){
                                                        
                                                        ?>
                                                        <input class="form-customer-create-button" type="submit" name="save" value="Speichern"/>
                                                        <?php
                                                            }
                                                        }
                                                        ?>
                                                        <input class="form-customer-create-button" type="submit" name="mark" value="zur Freigabe vormerken"/>
                                                    </div>
                                            </div>

                                            <!-- Clear Div -->
                                            <div class="clear"></div>
                                            <!-- Clear Div End -->
                                            </div>
                                            <!-- Form element wrap end -->

                                            <!-- ########################################################## -->

                                    </form>
                                    <!-- Form End -->
                            </div>
                            <!-- 2 columns end -->

                    </div>
                    <!-- EDIT FORM END -->
                    <?php } // end-if($show_editForm) ?>
<?php
            } //if ( $customer != 0 ){ ENDS
    }//if ( isset($_GET['kunden-nr']) ){ ENDS

//---------------------------------------
//-----TABLE WITH SELECTED CUSTOMER END--
//---------------------------------------

//---------------------------------------
//-----TABLE WITH CUSTOMERS--------------
//---------------------------------------
    if ( $showCustomerTable ){
        
        $action = array("edit");
        $customers = $db->getCustomers("edit", $staff, $gstelle);//get/select editable customers
        include_once("customer_table.php");

    }
//    if ( $showCustomerTable ){
//        $action = array("edit");
//        if ( isset($_GET['action']) ){
//            if ( $_GET['action'] == "mark" ){
//                    $customers = $db->getCustomers("edit-m", $staff, $gstelle);//get/select editable customers
//                    include_once("customer_table.php");
//            }elseif( $_GET['action'] == "edit" ){
//                    $customers = $db->getCustomers("edit-e", $staff, $gstelle);//get/select editable customers
//                    include_once("customer_table.php");
//            }
//        }
//        
//    }
//---------------------------------------
//-----TABLE WITH CUSTOMERS END----------
//---------------------------------------
?>
<!-- JAVASCRIPT -->
<script>
    $(function() {
            $( "#datepicker_livingsince" ).datepicker({ dateFormat: 'dd.mm.yy' });
            $( "#datepicker_birthday" ).datepicker({ dateFormat: 'dd.mm.yy' });
    });
    //dasdasd
    $(document).ready(function(){

            $("#sector_group").change(onSelectChange_sector_group);
            
            onSelectChange_sector_group();

    });
    function onSelectChange_sector_group(){
            var sector_group = $("#sector_group option:selected");
            
            if( sector_group.val() == 1 || sector_group.val() == 2 ||
                sector_group.val() == 3 || sector_group.val() == 4 ||
                sector_group.val() == 5 || sector_group.val() == 11
            ){
                $("#sector").show();
                if( sector_group.val() == 5 || sector_group.val() == 11 ){
                    $("#occupation").show();
                    $("#sector").width(385);
                }else{
                    $("#sector").width(770);
                    $("#occupation").hide();
                    $("#sb_occupation").val(0);
                }
                
            }else{
                $("#sb_sector").val(0);
                $("#sector").hide();
                $("#sector").width(385);
                
                $("#sb_occupation").val(0);
                $("#occupation").hide();
            }
    }
</script>
<!-- JAVASCRIPT END -->